/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ASAExpr;

import exception.DivisionByZeroException;
import exception.VariableNonDeclareeException;

/**
 *
 * @author FM & KB
 */
public class ASAExprMod extends ASAExpr {

    private ASAExpr e1;
    private ASAExpr e2;

    public ASAExprMod(ASAExpr e1, ASAExpr e2) {
        this.e1 = e1;
        this.e2 = e2;
    }

    public ASAExpr getExpr1() {
        return e1;
    }

    @Override
    public ASAExpr getExpr2() {
        return e2;
    }

    public int evalue() throws VariableNonDeclareeException, DivisionByZeroException {
        return e1.evalue() % e2.evalue();
    }

    @Override
    public String getLabelExplorateur() {
        return "MODULO";
    }

    public ASAExpr simplifie() throws VariableNonDeclareeException, DivisionByZeroException {
        ASAExpr se1 = e1.simplifie();
        ASAExpr se2 = e2.simplifie();
        if (se1 instanceof ASAExprEntier && se2 instanceof ASAExprEntier) {
            return new ASAExprEntier(se1.evalue() % se2.evalue());
        }

        if (se2.getClass() != ASAExprRecupIdent.class) {
            if (se2.evalue() == 0) {
                return new ASAExprEntier(0);
            }
        }

        if (se1.getClass() != ASAExprRecupIdent.class) {
            if (se1.evalue() == 0) {
                return new ASAExprEntier(0);
            }
        }
        return new ASAExprMod(se1, se2);
    }
}
